package com.dferreira.languagesteach.fragments;

import com.dferreira.languagesteach.data_adapters.WorkoutsAdapter;
import com.dferreira.languagesteach.fragments.generic.NavigationListFragment;
import com.dferreira.languagesteach.utils.DefaultLanguagesData;
import com.dferreira.repository.Repository;

/**
 * Created by dferreira on 5/29/14.
 * for LanguagesTeach
 */
public class WorkoutsFragment extends NavigationListFragment {
    @SuppressWarnings("FieldCanBeLocal")
    private WorkoutsAdapter workoutsAdapter;

    @Override
    public void onStart() {

        Boolean buildResult;
        DefaultLanguagesData defaultLanguagesData;
        String defaultPackageName;
        Repository repository;

        repository = new Repository(getActivity());

        super.onStart();

        defaultLanguagesData = new DefaultLanguagesData(getActivity());

        defaultPackageName = defaultLanguagesData.getDefaultPackagesMetadata()[0]
                .getName();

        workoutsAdapter = new WorkoutsAdapter(getActivity(),getPackageFolder());

        buildResult = workoutsAdapter.buildDataSet(repository.getInstalledPackageInfo(defaultPackageName)
                        .getInstalledPath()
        );

        if (buildResult) {
            setListAdapter(workoutsAdapter);
        } else {
            getActivity().onBackPressed();
        }
    }
}
